package com.leetcode.LC;

import java.util.ArrayList;
import java.util.List;

public class LC690 {


    ArrayList<Integer> list = new ArrayList<>();
    public int getImportance(List<Employee> employees, int id) {
        int sum=0;
        for (Employee employee : employees) {
            if (employee.id == id) {
                getStaff(employees,employee);
            }
        }
        for (Integer integer : list) {
            sum+=integer;
        }
        return sum;
    }
    public void getStaff(List<Employee> employees,Employee employee) {

        list.add(employee.importance);
        if (employee.subordinates.size() > 0) {
            for (Integer subordinate : employee.subordinates) {
                getStaff(employees,getEmployeeById(employees,subordinate));
            }
        }
    }
    public Employee getEmployeeById(List<Employee> employees, int id){
        for (Employee employee : employees) {
            if (employee.id == id) {
                return employee;
            }
        }
        return null;
    }
}
class Employee {
    public int id;
    public int importance;
    public List<Integer> subordinates;
};